package com.example.job.Repository


import android.annotation.SuppressLint
import android.content.Context
import com.example.job.Model.JobModel
import com.example.job.db.jobdb

class JobDataRepository(private val context: Context) {
    @SuppressLint("Range")
    fun getJobs(): List<JobModel> {
        val dbHelper = jobdb(context)
        val db = dbHelper.readableDatabase
        val cursor = db.query(
            "jobs",
            null,
            null,
            null,
            null,
            null,
            null
        )

        val jobs = mutableListOf<JobModel>()
        while (cursor.moveToNext()) {
            val job = JobModel(
                cursor.getInt(cursor.getColumnIndex("id")),
                cursor.getString(cursor.getColumnIndex("title")),
                cursor.getString(cursor.getColumnIndex("company_title")),
                cursor.getString(cursor.getColumnIndex("type")),
                cursor.getString(cursor.getColumnIndex("min_salary")),
                cursor.getString(cursor.getColumnIndex("max_salary")),
                cursor.getString(cursor.getColumnIndex("experience")),
                cursor.getString(cursor.getColumnIndex("edu")),
                cursor.getString(cursor.getColumnIndex("tag")),
                cursor.getString(cursor.getColumnIndex("people")),
                cursor.getString(cursor.getColumnIndex("flag")),
                cursor.getString(cursor.getColumnIndex("welfare")),
                cursor.getString(cursor.getColumnIndex("img")),
                cursor.getString(cursor.getColumnIndex("city"))
            )
            jobs.add(job)
        }
        cursor.close()
        db.close()

        return jobs
    }

}